<?php

namespace app\admin\model\model\system;

use app\admin\model\traits\Common;
use think\db\BaseQuery as Query;
use think\Model;

class SystemMenu extends Model
{
	use Common;

    CONST STATUS_SHOW = 1;
    CONST STATUS_HIDE = 0;

    const ORDER_DEFAULT = 'sort desc';

    public function scopeStatusShow(Query $query) {
        return $query->where('status', self::STATUS_SHOW)->order(self::ORDER_DEFAULT);
    }

    public static function getIdByUrl($url) {
        $where = [
            'url' => $url,
        ];
        return self::getValueCommon($where, 'id');
    }

	public static function status($id, $status) {
		$data = [
			'id' => $id,
			'status' => $status,
		];
		return self::updateCommon($data);
	}

	public static function getAllStatus($ids=false) {
        $where = [];
        if($ids !== false) {
            $where = [
                ['id', 'in', $ids],
            ];
        }

		return self::scope('statusShow')->where($where)->select();
	}

    public function getId() {
        return $this->getData('id');
    }

    public function getPid() {
        return $this->getData('pid');
    }

    public function getTitle() {
        return $this->getData('name');
    }
}